﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using System.Configuration;
using Crosland.Automotriz.Seguridad.Entity;
using Crosland.Automotriz.Logic;
using Crosland.Automotriz.Core;
using System.Security.Principal;
using System.Net;
using Crosland.Automotriz.Seguridad.Business;
using Crosland.Automotriz.Facade.Interface;
using Crosland.Automotriz.Facade.Facade;

namespace Crosland.Automotriz.Web.Vehiculos.Popup
{
    public partial class wFrmPopupImpresionCartaMedioPago : BaseForm
    {
        iFacadeCompensacionVehiculo BL_CompensacionVehiculo = new FacadeCompensacionVehiculo();

        protected override void Inicializar()
        {
            int factura = Convert.ToInt32(Session["FacturaVehiculo"]);
            int representante = Convert.ToInt32(Session["RL"]);

            this.rvPopupReporte.ShowPrintButton = false;//Oculta el boton imprimir

            this.rvPopupReporte.ProcessingMode = ProcessingMode.Remote;
            this.rvPopupReporte.ShowCredentialPrompts = true;
            this.rvPopupReporte.ShowExportControls = true;
            this.rvPopupReporte.ServerReport.ReportServerCredentials = new RSCredentials();
            this.rvPopupReporte.ServerReport.ReportServerUrl =
                new Uri(ConfigurationManager.AppSettings[DatosConfiguracion.RsServer]);
            this.rvPopupReporte.ServerReport.ReportPath = "/SAP_Vehiculos/rs_CartaMedioPago";

            ReportParameter parameter = new ReportParameter("FACTURA",factura.ToString());
            ReportParameter parameter2 = new ReportParameter("Representante", representante.ToString());

            this.rvPopupReporte.ServerReport.SetParameters(parameter);
            this.rvPopupReporte.ServerReport.SetParameters(parameter2);
        }

        [Serializable]
        public sealed class RSCredentials : IReportServerCredentials
        {
            public WindowsIdentity ImpersonationUser
            {
                get { return null; }
            }

            public ICredentials NetworkCredentials
            {
                get
                {
                    string userName = ConfigurationManager.AppSettings[DatosConfiguracion.RsUser];
                    string password = ConfigurationManager.AppSettings[DatosConfiguracion.RsPassword];
                    string domain = ConfigurationManager.AppSettings[DatosConfiguracion.RsDomain];

                    return new NetworkCredential(userName, password, domain);
                }
            }

            public bool GetFormsCredentials(out Cookie authCookie, out String userName, out String password,
                out String authority)
            {
                authCookie = null;
                userName = null;
                password = null;
                authority = null;
                return false;
            }
        }

        protected void btnSalir_Click(object sender, EventArgs e)
        {
            string script = "CerrarVentana();";
            ScriptManager.RegisterStartupScript(this, typeof(Page), "cerrar", script, true);
        }

        protected void btnImprimir_Click(object sender, EventArgs e)
        {
            T_VEN_CARTAS_VEH_IMPRESION entity = new T_VEN_CARTAS_VEH_IMPRESION();

            entity.ID_ORG_VTA=3;
            entity.ID_OFI_VTA=17;
            entity.NRO_FACTURA = Convert.ToInt32(Session["FacturaVehiculo"]);
            entity.IND_IMPR_CMP = 1;
            entity.IND_IMPR_CT = null;

            BL_CompensacionVehiculo.GuardarImpresionCMPCT(entity);
            
        }



    }
}